Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Getting "Cannot set headers after they are sent to the client" error in Express

Screenshot of the error:

Screenshot of the error

Code of client side:

Code of client side

jwt attached api:

jwt attached api

Here's the jwt verifying function:

    const authHeader = req.headers?.authorization;
    if(!authHeader){
        return res.status(401).send({message: 'Unauthorized access'})
    }
    const token = authHeader.split(' ')[1];
    jwt.verify(token, process.env.SECRET_TOKEN, (err, decoded)=>{
        if(err){
            return res.status(403).send({message: 'Forbidden access'})
        }
        console.log('decoded', decoded);
        req.decoded = decoded;
    })
    next();
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This error isn't related to jwt. This error happens if you try to do something with res object after response is sent. You can try to use return statement after or along with all your res.send() statements on server and that should resolve this error.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda